using System;
using System.IO;
using DesignPatternDefinitions;

namespace CodeGenerators
{
	internal class DefaultProjectGenerator : IDPAProjectGenerator
	{
		#region IDPAProjectGenerator Members
		public virtual string GenerateProjectFile(string directory, DesignPatternDefinitions.IProject project)
		{
			string projectRoot = directory + "\\" + project.ProjectName;
			if( ! Directory.Exists( projectRoot ) )
				Directory.CreateDirectory( projectRoot );
			CreateReadmeFile(projectRoot,project);
			return projectRoot;
		}
		#endregion

		#region Implementation Functions
		
		private void CreateReadmeFile(string projectRoot, IProject project)
		{
			try
			{
				string filename = projectRoot + "\\Readme.txt" ;
				StreamWriter writer = new StreamWriter(filename);
				writer.WriteLine( "Name : {0}" , project.ProjectName );
				writer.WriteLine( "Author : {0}" , project.ProjectAuthor );
				writer.WriteLine( "Summary : {0}" , project.ProjectSummary );
				writer.Close();
			}
			catch
			{

			}
		}
		#endregion
	}
}
